#!/usr/bin/env python
# -*- encoding: UTF-8 -*-

from __future__ import print_function

import os

from flask import Flask
from flask_bootstrap import Bootstrap
from flask_mail import Mail
from flask_moment import Moment
from flask_sqlalchemy import SQLAlchemy
from flask_restful import Api

from config import config

bootstrap = Bootstrap()
mail = Mail()
moment = Moment()
db = SQLAlchemy()
api = Api()
global_dict = {}
basedir = os.path.abspath(os.path.dirname(__file__))

import sys
def myprint(*args):
    print(*args,file=sys.stderr) # 用来在运行时 print 到标准（错误）输出

def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    config[config_name].init_app(app)

    bootstrap.init_app(app)
    mail.init_app(app)
    moment.init_app(app)
    db.init_app(app)
    #api.init_app(app)
    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)
    from .resources import api_bp
    app.register_blueprint(api_bp)

    return app

class MyFlag(object):
    def __init__(self):
        class Image: # 图像标记
            def __init__(self):
                self.calibration = "calibration" # 单目标定图像标记
                self.collect = "collect" # 图像采集标记
        self.image = Image()

flag=MyFlag()